#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include"xh.h"

UF Initilailize(int size) {
	int i = 0;
	UF uf=malloc(sizeof(struct UnionFind));
	if (uf == NULL) {
		perror("malloc");
		return NULL;
	}
	uf->arr = (ElementType *)malloc(size*sizeof(ElementType));
	if (uf->arr == NULL) {
		perror("malloc");
		return NULL;
	}
	for (i = 0; i < size; i++) {
		uf->arr[i] = 0;
	}
	uf->size = size;
	uf->CC = size;
	return uf;
}

void Union(UF uf, SetType root1, SetType root2) {
	if (root2<0 || root2>uf->size || uf == NULL) {
		printf("Union is error!");
		return;
	}
	int i = 0;
	
	if (root2==root1)
		return;

	uf->arr[root2] = root1;
	uf->CC--;
}

SetType Find(UF uf, ElementType X) {
	if (uf->arr[X] <= 0) {
		return X;
	}
	else
		return Find(uf, uf->arr[X]);
}